#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :数据库操作.py
# @Time      :2023/10/16 
# @Author    :CL
# @email     :1037654919@qq.com
from utils import mongo_manager
def expert_data():
    qq_category_list = mongo_manager('qq_category_list')
    qq_sub_category_list = mongo_manager('qq_sub_category_list')

    seeds = qq_category_list.findAll()
    for seed in seeds:
        for children in seed['children']:
            data ={}
            data['_id'] = children['id']
            data['father_id'] = seed['id']
            data['father_name'] = seed['name']
            data["sub_category_id"] = children['id']
            data["sub_category_name"] = children['name']
            try:
                data['status'] = seed['status']
            except:
                data['status'] = None
            try:
                qq_sub_category_list.insertOne(data)
            except:
                pass

# 增加字段maxpages



    qq_sub_category_list.close()
def get_maxpage():
    from get_book_list import get_book_list
    qq_sub_category_list = mongo_manager('qq_sub_category_list')
    seeds = qq_sub_category_list.findAll({'maxpage':None})
    for seed  in seeds:
        print(seed)
        params = {
            "page": "1",
            "category_id": seed['father_id'],
            "sub_category_id": seed['_id']
        }
        book_list = get_book_list(params=params)
        datas = book_list['data']['book_list']
        seed['maxpage'] = book_list['data']['max_page']
        qq_sub_category_list.updateOne({'_id':seed['_id']},seed)
    qq_sub_category_list.close()

if __name__ == '__main__':
    print()
    get_maxpage()